home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1996 February
/
EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso
/
earcd
/
comm2
/
kms20src.lha
/
KMSC
/
filebase.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-04-04
|
40KB
|
1,441 lines
/**********************************
* KMS *
**********************************
* ©1992 by BlackMagic Software *
**********************************
* *
**********************************/
#include <KMS/KMS.h>
#include <KMS/KMS_devlib.h>
Prototype VOID Upload(UBYTE);
Prototype VOID Download(UMSMsgNum, UBYTE, STRPTR);
Prototype VOID XPRReceive(VOID);
Prototype BOOL XPRSend(VOID);
Prototype BOOL MoveBin(UMSMsgNum, struct AreaNode *, BOOL);
Prototype struct Window *GetWindow(VOID);
Prototype UBYTE ProtSelect(BOOL);
Prototype VOID DeleteBinary(UMSMsgNum, struct AreaNode *);
Prototype VOID BatchUpload(VOID);
Prototype VOID MsgUpload(VOID);
Prototype BOOL LocalDownload(VOID);
extern VOID KPrintF(APTR, ...);
/*****************************
* Externe Globale Variablen *
*****************************/
extern struct KMSBase *KMSBase;
extern struct LocalConfig *KMS_LC;
extern STRPTR PPArg, PPArg2, PPArg3;
extern UBYTE ShutDown, Plop;
extern UMSAccount MyUMSAccount, SysUMSAccount;
extern UMSMsgNum Lastmsg;
extern struct TagItem UMSReadTags[];
extern struct TagItem UMSListTags[];
extern struct MessageInfo RMsgInfo;
extern STRPTR RAttributes;
extern STRPTR RGroup;
extern STRPTR RSubject;
extern TEXT KMSTempDat[];
/*********************
* Globale Variablen *
*********************/
struct Library *AslBase;
static struct FileRequester *FileRequester;
TEXT BinaryName[LEN_DOSPATH+1];
ULONG BinarySize;
/********************************
* Upload *
********************************
* I: flag *
* O: --- *
********************************/
/// "Upload"
VOID Upload(UBYTE flag)
{
struct Window *mywin;
TEXT frompath[LEN_DOSPATH+1];
TEXT topath[LEN_DOSPATH+1];
TEXT sizebuff[LEN_NUMBER+1];
BOOL success = FALSE;
struct AreaNode *current = KMS_LC->Session.CurrentArea;
ULONG filesize;
STRPTR fromfile, filename;
if (!flag)
{
/* Zugriff prüfen */
if (!(current->AreaData.Type & (ATYPE_FILES|ATYPE_PRIVATE)))
{
SysMsg(NO_FILE_AREA);
return;
}
if (!(CheckAccess(current) & AACC_WRITE))
{
PPArg = KMS_LC->Session.InputBuffer;
SysMsg(NO_WRITE_ACCESS);
PPArg = NULL;
return;
}
}
/* File besorgen */
if (KMS_LC->Device & DEV_CONSOLE)
{
/* Lokaler File-Requester, empfangene Dateien nach KMSBase->TempDir */
if (mywin = GetWindow())
{
if (AslBase = OpenLibrary(AslName, 36))
{
if (FileRequester = AllocAslRequestTags(ASL_FileRequest, ASL_Hail, "Select files to upload...",
ASL_Window, mywin,
ASL_FuncFlags, FILF_MULTISELECT,
TAG_DONE))
{
if (AslRequest(FileRequester, NULL))
{
LONG numfiles = FileRequester->rf_NumArgs;
struct WBArg *filelist = FileRequester->rf_ArgList;
if (!numfiles || !filelist)
success = TRUE; /* Damit unten keine Fehlermeldung */
while(filelist && numfiles)
{
*frompath = '\0';
success = FALSE;
strcpy(frompath, FileRequester->rf_Dir);
AddPart(frompath, filelist->wa_Name, sizeof(frompath));
fromfile = filelist->wa_Name;
if (*frompath)
{
/* Datei nach TempDir kopieren */
sprintf(topath, "%s%s", KMSBase->TempDir, fromfile);
if (Copy(frompath, topath, FALSE))
success = TRUE;
}
if (filelist)
filelist++;
numfiles--;
if (!success || (flag & UL_MSG))
numfiles = 0;
}
}
else
success = TRUE; /* Damit unten keine Fehlermeldung */
FreeFileRequest(FileRequester);
}
CloseLibrary(AslBase);
}
}
if (!success)
SystemError("Upload", "Local");
}
else
{
/* Remote Dateitransfer, empfangene Dateien nach KMSBase->TempDir */
XPRReceive();
}
/* Dateinamen aus KMSBase->TempDir einlesen und abarbeiten */
LONG more;
BPTR mylock;
struct ExAllData *eadata, *ead;
eadata = (struct ExAllData *)AllocMem(LEN_EADATA, MEMF_CLEAR);
if (!eadata)
{
SystemError("Upload", "AllocMem");
return;
}
if (!(mylock = Lock(KMSBase->TempDir, SHARED_LOCK)))
{
FreeMem(eadata, LEN_EADATA);
SystemError("Upload", "Lock");
return;
}
struct ExAllControl *eac = AllocDosObject(DOS_EXALLCONTROL, NULL);
if (!eac)
{
UnLock(mylock);
FreeMem(eadata, LEN_EADATA);
SystemError("Upload", "AllocDosObject");
return;
}
eac->eac_LastKey = 0;
eac->eac_MatchString = NULL;
eac->eac_MatchFunc = NULL;
do {
more = ExAll(mylock, eadata, LEN_EADATA, ED_SIZE, eac);
/* If non-zero is returned, you MUST call ExAll again until
it returns FALSE. */
if (more == DOSFALSE && IoErr() != ERROR_NO_MORE_ENTRIES)
break;
else if (eac->eac_Entries == 0)
continue;
ead = eadata;
do {
filename = ead->ed_Name;
filesize = ead->ed_Size;
strcpy(frompath, KMSBase->TempDir);
strcat(frompath, filename);
sprintf(sizebuff, "%ld", filesize);
ConvertSpace(filename);
PPArg = filename;
PPArg2 = sizebuff;
SysMsg(UPLOAD_WORKING);
PPArg = NULL;
PPArg2 = NULL;
if (filesize)
{
if (flag & UL_PRIV)
{
strcpy(topath, KMSBase->UserDir);
strcat(topath, KMS_LC->Session.CurrentUser->UserData.Name);
ConvertSpace(topath);
LONG quota = DirWork(topath, "~(#?.KMS)", 0);
quota = KMS_LC->Session.CurrentUser->UserData.Quota * 1024L - quota - filesize;
if (quota < 0)
SysMsg(QUOTA_EXCEEDED);
else
{
strcat(topath, "/");
strcat(topath, filename);
if (Exists(topath))
SysMsg(BINARY_EXISTS);
else
{
/* Datei umsetzen von frompath nach topath */
if (!Copy(frompath, topath, FALSE))
SystemError("Upload", "Move");
else
SysMsg(UPLOAD_SUCCESSFUL);
}
}
}
else if (flag & UL_MSG)
{
/* Datei umsetzen von frompath nach KMSTempDat */
if (!Copy(frompath, KMSTempDat, FALSE))
SystemError("Upload", "Move");
else
SysMsg(UPLOAD_SUCCESSFUL);
}
else
{
strcpy(topath, current->AreaData.FilePath);
if (topath[strlen(topath)-1] != ':' && topath[strlen(topath)-1] != '/')
strcat(topath, "/");
strcat(topath, filename);
if (Exists(topath))
SysMsg(BINARY_EXISTS);
else
{
/* Beschreibung besorgen */
strcpy(BinaryName, filename);
BinarySize = filesize;
if (WriteMsg(WF_NEW|WF_BINARY, NULL, NULL, NULL))
{
/* Datei umsetzen von frompath nach topath */
if (!Copy(frompath, topath, FALSE))
SystemError("Upload", "Move");
}
}
}
}
DeleteFile(frompath);
ead = ead->ed_Next;
} while(ead);
} while(more == DOSTRUE);
FreeDosObject(DOS_EXALLCONTROL, eac);
UnLock(mylock);
FreeMem(eadata, LEN_EADATA);
}
///
/********************************
* Download *
********************************
* I: Msg-Nr., Flag, Dateiname *
* O: --- *
********************************/
/// "Download"
/* DOWN_XFER \ DOWN_PRIVATE
DOWN_LIST \ DOWN_CURRENT
DOWN_SELECT / DOWN_SELECTED
DOWN_DESELECT / DOWN_RANGE */
VOID Download(UMSMsgNum num, UBYTE flag, STRPTR privname)
{
TEXT frompath[LEN_DOSPATH+1];
struct AreaNode *current = KMS_LC->Session.CurrentArea;
STRPTR arg;
STRPTR rsubject = "";
TEXT fname[LEN_DOSFILE+1];
TEXT fsizebuff[LEN_NUMBER+1];
TEXT buff[LEN_MAXLINE+1];
ULONG fsize, sumsize;
UWORD avgsecs, avgmin;
FILE *logfile;
BOOL titel = TRUE;
/* UMSUSTATF_PostPoned: Markierte Binärfiles */
if (flag & (DOWN_CURRENT|DOWN_RANGE))
{
/* Zugriff prüfen */
if (!(current->AreaData.Type & (ATYPE_FILES|ATYPE_PRIVATE)))
{
SysMsg(NO_FILE_AREA);
return;
}
if (!(KMS_LC->Session.CurrentAccess & AACC_READ))
{
PPArg = KMS_LC->Session.InputBuffer;
SysMsg(NO_READ_ACCESS);
PPArg = NULL;
return;
}
SelectArea(KMS_LC->Session.CurrentArea->AreaData.MBName);
if (!(flag & DOWN_RANGE))
{
if (!num && !(num = Lastmsg))
{
SysMsg(NO_MSG_READ);
return;
}
/* Nachricht vorhanden? */
UMSReadTags[0].ti_Data = num;
if (!ReadUMSMsg(MyUMSAccount, &UMSReadTags[0])
|| !(RMsgInfo.msgi_LoginStatus & KMSLSTATF_Visible))
{
SysMsg(MSG_NOT_FOUND);
FreeUMSMsg(MyUMSAccount, num);
return;
}
/* Msg in aktueller Gruppe? */
if (!(RMsgInfo.msgi_LoginStatus & KMSLSTATF_InGroup))
{
SysMsg(MSG_NOT_IN_AREA);
FreeUMSMsg(MyUMSAccount, num);
return;
}
/* Binärfile? */
fsize = 0;
*fname = '\0';
*fsizebuff = '\0';
if (RAttributes)
{
/* "KMS_FNAME:abcd... KMS_FSIZE:12345..." */
if (arg = strstr(RAttributes, "KMS_FNAME:"))
{
sscanf(arg, "KMS_FNAME:%30s", fname);
if (arg = strstr(RAttributes, "KMS_FSIZE:"))
sscanf(arg, "KMS_FSIZE:%d", &fsize);
}
}
/* Fileinfo aufbereiten */
strcpy(frompath, current->AreaData.FilePath);
if (frompath[strlen(frompath)-1] != ':' && frompath[strlen(frompath)-1] != '/')
strcat(frompath, "/");
strcat(frompath, fname);
if (!Exists(frompath))
fsize = 0;
if (!fsize)
strcpy(fsizebuff, "????");
else if (fsize < 10000)
sprintf(fsizebuff, "%4d", fsize);
else
{
fsize /= 1024;
if (fsize < 1000)
sprintf(fsizebuff, "%3dK", fsize);
else
{
fsize /= 1024;
sprintf(fsizebuff, "%3dM", fsize);
}
}
sprintf(buff, "%5ld %s %-20.20s ", num, fsizebuff, fname);
if (strlen(buff) < KMS_LC->Session.CurrentUser->UserData.LineLen)
{
if (RSubject)
rsubject = RSubject;
strncat(buff, rsubject, KMS_LC->Session.CurrentUser->UserData.LineLen - strlen(buff));
buff[KMS_LC->Session.CurrentUser->UserData.LineLen] = '\0';
}
strcat(buff, "\n");
FreeUMSMsg(MyUMSAccount, num);
if (!fsize)
{
SysMsg(NO_BINARY_ATTACHED);
return;
}
}
}
if ((flag & DOWN_XFER) && (flag & (DOWN_CURRENT|DOWN_PRIVATE)))
{
if (flag & DOWN_CURRENT)
{
/* Fileinfo ausgeben */
SysMsg(SELBIN_HEAD);
MsgPrint(buff, 0);
Print(NULL, PF_NOBRK);
}
else
{
sprintf(frompath, "%s%s/%s",
KMSBase->UserDir,
KMS_LC->Session.CurrentUser->UserData.Name,
privname);
ConvertSpace(frompath);
if (!Exists(frompath))
{
SysMsg(FILE_NOT_FOUND);
return;
}
else
{
strcpy(fname, privname);
PPArg = fname;
SysMsg(DOWNLOAD_PRIV);
PPArg = NULL;
}
}
/* Dateipfad in "T:FILES.KMS" schreiben und Transfer starten */
logfile = fopen("T:FILES.KMS", "w");
if (logfile)
{
BOOL success;
fprintf(logfile, "%s\n", frompath);
fclose(logfile);
if (KMS_LC->Device & DEV_SERIAL)
success = XPRSend();
else
success = LocalDownload();
DeleteFile("T:FILES.KMS");
if (success)
{
/* Als gelesen markieren */
UMSSelectTags(MyUMSAccount, UMSTAG_SelMsg, num,
UMSTAG_SelSet, UMSUSTATF_Old,
TAG_DONE);
UMSSelectTags(MyUMSAccount, UMSTAG_SelMsg, num,
UMSTAG_SelWriteLocal, TRUE,
UMSTAG_SelUnset, KMSLSTATF_Unread,
TAG_DONE);
}
}
else
SystemError("Download", "Logwrite");
}
else if ((flag & (DOWN_XFER|DOWN_LIST)) && (flag & (DOWN_RANGE|DOWN_SELECTED)))
{
/* Download/Liste aller selektierten Binärfiles oder Nummern-Bereich */
ULONG umsflag;
ULONG umslocal;
if (flag & DOWN_SELECTED)
{
umsflag = UMSUSTATF_PostPoned;
umslocal = TAG_IGNORE;
}
else
{
umsflag = KMSLSTATF_InRange;
umslocal = UMSTAG_SearchLocal;
}
sumsize = 0;
num = 0;
while(num = UMSSearchTags(MyUMSAccount, UMSTAG_SearchLast, num,
UMSTAG_SearchDirection, 1,
umslocal, TRUE,
UMSTAG_SearchMask, umsflag,
UMSTAG_SearchMatch, umsflag,
TAG_DONE))
{
UMSReadTags[0].ti_Data = num;
/* Nächste passende Msg einlesen */
/* Weiter nur, wenn Nachricht sichtbar und KMS-Gruppe existiert */
if (ReadUMSMsg(MyUMSAccount, &UMSReadTags[0])
&& (RMsgInfo.msgi_LoginStatus & KMSLSTATF_Visible) && (current = AreaSearch(RGroup)))
{
if (titel)
{
if (flag & DOWN_SELECTED)
SysMsg(SELBIN_HEAD);
else
SysMsg(RANGEBIN_HEAD);
titel = FALSE;
}
strcpy(frompath, current->AreaData.FilePath);
if (frompath[strlen(frompath)-1] != ':' && frompath[strlen(frompath)-1] != '/')
strcat(frompath, "/");
/* File-Info extrahieren */
fsize = 0;
*fname = '\0';
*fsizebuff = '\0';
if (RAttributes)
{
/* "KMS_FNAME:abcd... KMS_FSIZE:12345..." */
if (arg = strstr(RAttributes, "KMS_FNAME:"))
{
sscanf(arg, "KMS_FNAME:%30s", fname);
if (arg = strstr(RAttributes, "KMS_FSIZE:"))
sscanf(arg, "KMS_FSIZE:%d", &fsize);
}
}
/* Fileinfo aufbereiten */
strcat(frompath, fname);
if (!Exists(frompath))
fsize = 0;
sumsize += fsize;
if (!fsize)
strcpy(fsizebuff, "????");
else if (fsize < 10000)
sprintf(fsizebuff, "%4d", fsize);
else
{
fsize /= 1024;
if (fsize < 1000)
sprintf(fsizebuff, "%3dK", fsize);
else
{
fsize /= 1024;
sprintf(fsizebuff, "%3dM", fsize);
}
}
sprintf(buff, "%5ld %s %-20.20s ", num, fsizebuff, fname);
if (strlen(buff) < KMS_LC->Session.CurrentUser->UserData.LineLen)
{
if (RSubject)
rsubject = RSubject;
strncat(buff, rsubject, KMS_LC->Session.CurrentUser->UserData.LineLen - strlen(buff));
buff[KMS_LC->Session.CurrentUser->UserData.LineLen] = '\0';
}
strcat(buff, "\n");
/* Fileinfo ausgeben */
MsgPrint(buff, 0);
/* Zum Empfang vorbereiten */
if ((flag & DOWN_XFER) && fsize) /* Wenn nicht nur Liste und vorhanden */
{
/* Dateipfad und Name in "T:FILES.KMS" schreiben */
logfile = fopen("T:FILES.KMS", "a");
if (logfile)
{
fprintf(logfile, "%s\n", frompath);
fclose(logfile);
}
else
SystemError("Download", "Logwrite");
}
FreeUMSMsg(MyUMSAccount, num);
}
}
if (titel)
{
if (flag & DOWN_SELECTED)
SysMsg(NO_BINARY_SELECTED);
else
SysMsg(NO_BINARY_INRANGE);
}
else
{
/* Summary ausgeben */
sprintf(fsizebuff, "%ld", sumsize);
PPArg = fsizebuff;
SysMsg(TOTAL_BYTES);
PPArg = NULL;
if (KMS_LC->Device & DEV_SERIAL)
{
avgsecs = 0;
avgmin = 0;
if (KMS_LC->Session.LineSpeed)
avgsecs = sumsize * 8 / KMS_LC->Session.LineSpeed;
avgmin = avgsecs / 60;
avgsecs = avgsecs % 60;
if (KMS_LC->Session.LineSpeed)
sprintf(fsizebuff, "%02d:%02d", avgmin, avgsecs);
else
sprintf(fsizebuff, "??:??");
PPArg = fsizebuff;
SysMsg(ESTIMATED_TIME);
PPArg = NULL;
}
if (Exists("T:FILES.KMS"))
{
BOOL success;
/* Transfer starten */
if (KMS_LC->Device & DEV_SERIAL)
success = XPRSend();
else
success = LocalDownload();
if (success)
{
/* Alle deselektieren und als gelesen markieren */
if (flag & DOWN_SELECTED)
{
UMSSelectTags(MyUMSAccount, UMSTAG_SelMask, UMSUSTATF_PostPoned,
UMSTAG_SelMatch, UMSUSTATF_PostPoned,
UMSTAG_SelWriteLocal, TRUE,
UMSTAG_SelUnset, KMSLSTATF_Unread,
TAG_DONE);
UMSSelectTags(MyUMSAccount, UMSTAG_SelMask, UMSUSTATF_PostPoned,
UMSTAG_SelMatch, UMSUSTATF_PostPoned,
UMSTAG_SelUnset, UMSUSTATF_PostPoned,
UMSTAG_SelSet, UMSUSTATF_Old,
TAG_DONE);
}
else
{
UMSSelectTags(MyUMSAccount, UMSTAG_SelReadLocal, TRUE,
UMSTAG_SelMask, KMSLSTATF_InRange,
UMSTAG_SelMatch, KMSLSTATF_InRange,
UMSTAG_SelSet, UMSUSTATF_Old,
TAG_DONE);
UMSSelectTags(MyUMSAccount, UMSTAG_SelReadLocal, TRUE,
UMSTAG_SelWriteLocal, TRUE,
UMSTAG_SelMask, KMSLSTATF_InRange,
UMSTAG_SelMatch, KMSLSTATF_InRange,
UMSTAG_SelUnset, KMSLSTATF_InRange | KMSLSTATF_Unread,
TAG_DONE);
}
}
}
DeleteFile("T:FILES.KMS");
}
}
else if (flag & DOWN_SELECT)
{
/* Selektieren */
if (flag & DOWN_RANGE)
num = UMSSelectTags(MyUMSAccount, UMSTAG_SelReadLocal, TRUE,
UMSTAG_SelMask, KMSLSTATF_InRange,
UMSTAG_SelMatch, KMSLSTATF_InRange,
UMSTAG_SelSet, UMSUSTATF_PostPoned,
TAG_DONE);
else
num = UMSSelectTags(MyUMSAccount, UMSTAG_SelMsg, num,
UMSTAG_SelSet, UMSUSTATF_PostPoned,
TAG_DONE);
sprintf(buff, "%ld", num);
PPArg = buff;
SysMsg(BINARY_SELECTED);
PPArg = NULL;
}
else if (flag & DOWN_DESELECT)
{
/* Deselektieren */
if (flag & DOWN_RANGE)
num = UMSSelectTags(MyUMSAccount, UMSTAG_SelReadLocal, TRUE,
UMSTAG_SelMask, KMSLSTATF_InRange,
UMSTAG_SelMatch, KMSLSTATF_InRange,
UMSTAG_SelUnset, UMSUSTATF_PostPoned,
TAG_DONE);
else
num = UMSSelectTags(MyUMSAccount, UMSTAG_SelMsg, num,
UMSTAG_SelUnset, UMSUSTATF_PostPoned,
TAG_DONE);
sprintf(buff, "%ld", num);
PPArg = buff;
SysMsg(BINARY_DESELECTED);
PPArg = NULL;
}
}
///
/********************************
* XPRReceive *
********************************
* I: --- *
* O: --- *
********************************/
/// "XPRReceive"
VOID XPRReceive(VOID)
{
TEXT name[LEN_DOSFILE+1];
TEXT cmdline[LEN_MAXLINE+1];
TEXT cfgstring[20];
UBYTE prot;
ULONG result;
STRPTR des, lib, opt, cmd;
prot = ProtSelect(TRUE);
if (!prot)
return; /* User-Abbruch */
sprintf(cfgstring, "KMS.xprdescrip%d", prot);
des = ReadUMSConfigTags(SysUMSAccount, UMSTAG_CfgName, cfgstring, TAG_DONE);
sprintf(cfgstring, "KMS.xprlibrary%d", prot);
lib = ReadUMSConfigTags(SysUMSAccount, UMSTAG_CfgName, cfgstring, TAG_DONE);
sprintf(cfgstring, "KMS.xproptions%d", prot);
opt = ReadUMSConfigTags(SysUMSAccount, UMSTAG_CfgName, cfgstring, TAG_DONE);
strcpy(cfgstring, "KMS.xprcmdreceive");
cmd = ReadUMSConfigTags(SysUMSAccount, UMSTAG_CfgName, cfgstring, TAG_DONE);
if (!des || !lib || !opt || !cmd)
SystemError("XPRReceive", "Prot-Config");
else
{
/* Wenn nötig, Dateinamen anfordern */
if (des[strlen(des)-1] != '@')
{
result = CmdInput(NULL, PROMPT_FILENAME, " /:,*?#~[]()!\"\\", NULL, LEN_DOSFILE, INF_PROMPT|INF_EXCLUDE);
if (Plop || ShutDown || !result)
{
if (des)
FreeUMSConfig(SysUMSAccount, des);
if (lib)
FreeUMSConfig(SysUMSAccount, lib);
if (opt)
FreeUMSConfig(SysUMSAccount, opt);
if (cmd)
FreeUMSConfig(SysUMSAccount, cmd);
return;
}
strcpy(name, KMS_LC->Session.InputBuffer);
}
else
*name = '\0';
/* Jetzt der Transfer */
PPArg = lib;
PPArg2 = opt;
PPArg3 = name;
StdStringParse(cmd, cmdline, LEN_MAXLINE);
PPArg = NULL;
PPArg2 = NULL;
PPArg3 = NULL;
SystemCall(cmdline);
}
if (des)
FreeUMSConfig(SysUMSAccount, des);
if (lib)
FreeUMSConfig(SysUMSAccount, lib);
if (opt)
FreeUMSConfig(SysUMSAccount, opt);
if (cmd)
FreeUMSConfig(SysUMSAccount, cmd);
}
///
/********************************
* XPRSend *
********************************
* I: --- *
* O: Abbruch/Fehler: FALSE *
********************************/
/// "XPRSend"
BOOL XPRSend(VOID)
{
TEXT cmdline[LEN_MAXLINE+1];
TEXT frompath[LEN_DOSPATH+1];
TEXT fpaths[LEN_MAXLINE+1];
TEXT cfgstring[20];
STRPTR des, lib, opt, cmd, lst;
UBYTE prot = 0;
FILE *logfile = NULL;
BOOL success = FALSE;
UWORD maxflen = 0;
LONG sysres = 0;
prot = ProtSelect(TRUE);
if (!prot)
return FALSE; /* User-Abbruch */
sprintf(cfgstring, "KMS.xprdescrip%d", prot);
des = ReadUMSConfigTags(SysUMSAccount, UMSTAG_CfgName, cfgstring, TAG_DONE);
sprintf(cfgstring, "KMS.xprlibrary%d", prot);
lib = ReadUMSConfigTags(SysUMSAccount, UMSTAG_CfgName, cfgstring, TAG_DONE);
sprintf(cfgstring, "KMS.xproptions%d", prot);
opt = ReadUMSConfigTags(SysUMSAccount, UMSTAG_CfgName, cfgstring, TAG_DONE);
strcpy(cfgstring, "KMS.xprcmdsend");
cmd = ReadUMSConfigTags(SysUMSAccount, UMSTAG_CfgName, cfgstring, TAG_DONE);
strcpy(cfgstring, "KMS.xprcmdsendlist");
lst = ReadUMSConfigTags(SysUMSAccount, UMSTAG_CfgName, cfgstring, TAG_DONE);
if (!des || !lib || !opt || !cmd)
SystemError("XPRSend", "Prot-Config");
else
{
if (des[strlen(des)-1] == '@')
{
/* Batch-Transfer: Alle Dateien aus T:FILES.KMS */
if (!lst || !strlen(lst))
{
/* Alle Dateien in Kommandozeile auflisten */
/* Erstes Parsing ohne Dateinamen, um festzustellen, wieviel Platz
fuer die Dateipfade uebrig ist */
PPArg = lib;
PPArg2 = opt;
StdStringParse(cmd, cmdline, LEN_MAXLINE);
PPArg = NULL;
PPArg2 = NULL;
maxflen = sizeof(cmdline) - strlen(cmdline) - 1;
/* Jetzt Dateiliste erstellen */
logfile = fopen("T:FILES.KMS", "r");
if (logfile)
{
*fpaths = '\0';
while(fgets(frompath, LEN_DOSPATH, logfile))
{
frompath[strlen(frompath)-1] = '\0';
if (strlen(fpaths) + 1 + strlen(frompath) <= maxflen)
{
strcat(fpaths, frompath);
strcat(fpaths, " ");
}
else
{
/* Zweites Parsing mit Dateiliste */
PPArg = lib;
PPArg2 = opt;
PPArg3 = fpaths;
StdStringParse(cmd, cmdline, LEN_MAXLINE);
PPArg = NULL;
PPArg2 = NULL;
PPArg3 = NULL;
/* Kommandoaufruf */
sysres = SystemCall(cmdline);
/* Dateiliste mit zuletzt gelesenenem Pfad initialisieren */
strcpy(fpaths, frompath);
strcat(fpaths, " ");
}
}
/* Nochmal ein Parsing+Aufruf mit übrigen Dateien */
if (!sysres && strlen(fpaths))
{
PPArg = lib;
PPArg2 = opt;
PPArg3 = fpaths;
StdStringParse(cmd, cmdline, LEN_MAXLINE);
PPArg = NULL;
PPArg2 = NULL;
PPArg3 = NULL;
sysres = SystemCall(cmdline);
}
fclose(logfile);
if (!sysres)
success = TRUE;
else
success = FALSE;
}
else
SystemError("XPRSend", "ListRead");
}
else
{
/* Dateien werden in Listendatei an Sendekommando übergeben */
if (!Copy("T:FILES.KMS", lst, FALSE))
{
SystemError("XPRSend", "Copy <xprcmdsendlist>");
success = FALSE;
}
else
{
PPArg = lib;
PPArg2 = opt;
PPArg3 = lst;
StdStringParse(cmd, cmdline, LEN_MAXLINE);
PPArg = NULL;
PPArg2 = NULL;
PPArg3 = NULL;
/* Kommandoaufruf */
sysres = SystemCall(cmdline);
if (!sysres)
success = TRUE;
else
success = FALSE;
DeleteFile(lst);
}
}
}
else
{
/* Single-Transfer: Alle Dateien aus T:FILES.KMS einzeln */
logfile = fopen("T:FILES.KMS", "r");
if (logfile)
{
while(fgets(frompath, LEN_DOSPATH, logfile))
{
frompath[strlen(frompath)-1] = '\0';
PPArg = lib;
PPArg2 = opt;
PPArg3 = frompath;
StdStringParse(cmd, cmdline, LEN_MAXLINE);
PPArg = NULL;
PPArg2 = NULL;
PPArg3 = NULL;
sysres = SystemCall(cmdline);
}
fclose(logfile);
if (!sysres)
success = TRUE;
else
success = FALSE;
}
else
SystemError("XPRSend", "ListRead");
}
}
if (des)
FreeUMSConfig(SysUMSAccount, des);
if (lib)
FreeUMSConfig(SysUMSAccount, lib);
if (opt)
FreeUMSConfig(SysUMSAccount, opt);
if (cmd)
FreeUMSConfig(SysUMSAccount, cmd);
if (lst)
FreeUMSConfig(SysUMSAccount, lst);
return success;
}
///
/********************************
* Binärfile umsetzen *
********************************
* I: struct AreaNode *target *
* O: --- *
********************************/
/// "MoveBin"
BOOL MoveBin(UMSMsgNum source, struct AreaNode *target, BOOL sysop)
{
TEXT frompath[LEN_DOSPATH+1];
TEXT topath[LEN_DOSPATH+1];
struct AreaNode *current = KMS_LC->Session.CurrentArea;
STRPTR arg;
TEXT fname[LEN_DOSFILE+1];
BOOL error = FALSE;
if (!source)
return FALSE;
/* Zugriff prüfen */
if (!(target->AreaData.Type & ATYPE_FILES))
{
SysMsg(NO_FILE_AREA);
return FALSE;
}
if (!(CheckAccess(target) & AACC_WRITE))
{
PPArg = KMS_LC->Session.InputBuffer;
SysMsg(NO_WRITE_ACCESS);
PPArg = NULL;
return FALSE;
}
/* Filename besorgen */
UMSReadTags[0].ti_Data = source;
if (!ReadUMSMsg(MyUMSAccount, &UMSReadTags[0]))
{
SystemError("MoveBin", "ReadUMSMsg");
FreeUMSMsg(MyUMSAccount, source);
return FALSE;
}
if (!sysop)
{
if (!(RMsgInfo.msgi_UserStatus & UMSUSTATF_Owner))
{
SysMsg(MSG_NOT_OWNED);
FreeUMSMsg(MyUMSAccount, source);
return FALSE;
}
}
*fname = '\0';
if (RAttributes)
{
/* "KMS_FNAME:abcd... KMS_FSIZE:12345..." */
if (arg = strstr(RAttributes, "KMS_FNAME:"))
sscanf(arg, "KMS_FNAME:%30s", fname);
}
FreeUMSMsg(MyUMSAccount, source);
if (*fname)
{
/* Datei schon vorhanden? */
strcpy(topath, target->AreaData.FilePath);
if (topath[strlen(topath)-1] != ':' && topath[strlen(topath)-1] != '/')
strcat(topath, "/");
strcat(topath, fname);
if (Exists(topath))
{
SysMsg(BINARY_EXISTS);
return FALSE;
}
/* Datei umsetzen nach topath */
strcpy(frompath, current->AreaData.FilePath);
if (frompath[strlen(frompath)-1] != ':' && frompath[strlen(frompath)-1] != '/')
strcat(frompath, "/");
strcat(frompath, fname);
if (!Copy(frompath, topath, TRUE))
{
SystemError("MoveBin", "Move");
error = TRUE;
}
}
if (!error)
return CloneMsg(source, target, sysop);
else
return FALSE;
}
///
/********************************
* Fensteradresse besorgen *
********************************
* I: --- *
* O: struct Window * *
********************************/
/// "GetWindow"
struct Window *GetWindow(VOID)
{
__aligned struct InfoData info;
if (DoPkt(((struct FileHandle *)BADDR(KMS_LC->OutHandle))->fh_Type, ACTION_DISK_INFO, MKBADDR(&info), 0, 0, 0, 0))
return info.id_VolumeNode;
return NULL;
}
///
/********************************
* Übertragungsprotokoll wählen *
********************************
* I: Vorher fragen? *
* O: Protokoll-Nummer *
********************************/
/// "ProtSelect"
UBYTE ProtSelect(BOOL ask)
{
STRPTR string, temp;
TEXT cfgstring[20];
TEXT line[80];
TEXT tmp[2];
ULONG result;
UBYTE count = 1;
if (ask)
{
sprintf(cfgstring, "KMS.xprdescrip%d", KMS_LC->Session.CurrentUser->UserData.Protocol);
temp = ReadUMSConfigTags(SysUMSAccount, UMSTAG_CfgName, cfgstring, TAG_DONE);
if (temp)
{
strcpy(line, temp);
if (line[strlen(line)-1] == '@')
line[strlen(line)-1] = '\0';
PPArg2 = line;
CmdInput(NULL, PROMPT_CHANGEPROT, KMSBase->YNText, KMSBase->No, 1, INF_PROMPT|INF_UPCASE);
PPArg2 = NULL;
FreeUMSConfig(SysUMSAccount, temp);
if (Plop || ShutDown)
return 0;
if (*KMS_LC->Session.InputBuffer == KMSBase->YNText[NO])
return KMS_LC->Session.CurrentUser->UserData.Protocol;
}
}
SysMsg(PROTSEL_HEAD);
sprintf(cfgstring, "KMS.xprdescrip%d", count);
while(count < 10 && (string = ReadUMSConfigTags(SysUMSAccount, UMSTAG_CfgName, cfgstring, TAG_DONE)))
{
sprintf(line, "%1d) %s", count, string);
if (line[strlen(line)-1] == '@')
line[strlen(line)-1] = '\0';
Print(line, 0);
FreeUMSConfig(SysUMSAccount, string);
sprintf(cfgstring, "KMS.xprdescrip%d", ++count);
}
Print(NULL, 0);
if (KMS_LC->Session.CurrentUser->UserData.Protocol < count)
sprintf(tmp, "%1d", KMS_LC->Session.CurrentUser->UserData.Protocol);
else
strcpy(tmp, "0");
result = CmdInput(NULL, PROMPT_PROTSEL, NULL, tmp, 1, INF_PROMPT|INF_NUMERIC);
if (Plop || ShutDown)
return 0;
if (result > 0 && result < count)
{
KMS_LC->Session.CurrentUser->UserData.Protocol = result;
return result;
}
else
return 0;
}
///
/*********************************
* Anhängendes Binärfile löschen *
*********************************
* I: Msg-Nummer, Area *
* O: --- *
*********************************/
/// "DeleteBinary"
VOID DeleteBinary(UMSMsgNum msgnum, struct AreaNode *current)
{
STRPTR arg;
TEXT fname[LEN_DOSFILE+1];
TEXT frompath[LEN_DOSPATH+1];
/* Attributzeile besorgen */
if (!ReadUMSMsgTags(MyUMSAccount, UMSTAG_RMsgNum, msgnum,
UMSTAG_RAttributes, &RAttributes,
TAG_DONE))
{
FreeUMSMsg(MyUMSAccount, msgnum);
return;
}
/* Binärfile dran? */
if (RAttributes)
{
/* "KMS_FNAME:abcd... KMS_FSIZE:12345..." */
if (arg = strstr(RAttributes, "KMS_FNAME:"))
{
*fname = '\0';
sscanf(arg, "KMS_FNAME:%30s", fname);
strcpy(frompath, current->AreaData.FilePath);
if (frompath[strlen(frompath)-1] != ':' && frompath[strlen(frompath)-1] != '/')
strcat(frompath, "/");
strcat(frompath, fname);
/* Datei löschen */
DeleteFile(frompath);
}
}
FreeUMSMsg(MyUMSAccount, msgnum);
}
///
/*********************************
* Upload ins Privat-Verzeichnis *
*********************************
* I: --- *
* O: --- *
*********************************/
/// "BatchUpload"
VOID BatchUpload(VOID)
{
TEXT topath[LEN_DOSPATH+1];
TEXT sizebuff[LEN_NUMBER+1];
LONG quota;
strcpy(topath, KMSBase->UserDir);
strcat(topath, KMS_LC->Session.CurrentUser->UserData.Name);
ConvertSpace(topath);
quota = DirWork(topath, "~(#?.KMS)", 0);
quota = KMS_LC->Session.CurrentUser->UserData.Quota * 1024L - quota;
if (quota > 0 && quota < SIZE_QUOTAWARN)
{
sprintf(sizebuff, "%ld", quota);
PPArg = sizebuff;
SysMsg(QUOTA_WARNING);
PPArg = NULL;
}
else if (quota < 0)
SysMsg(QUOTA_EXCEEDED);
else
Upload(UL_PRIV);
}
///
/*********************************
* Message-Upload *
*********************************
* I: --- *
* O: --- *
*********************************/
/// "MsgUpload"
VOID MsgUpload(VOID)
{
Upload(UL_MSG);
}
///
/*********************************
* Filerequester-Download *
*********************************
* I: --- *
* O: Erfolg TRUE/FALSE *
*********************************/
/// "LocalDownload"
BOOL LocalDownload(VOID)
{
struct Window *mywin;
TEXT frompath[LEN_DOSPATH+1];
TEXT topath[LEN_DOSPATH+1];
STRPTR fname;
FILE *logfile;
logfile = fopen("T:FILES.KMS", "r");
if (logfile)
{
Print(NULL, 0);
if (mywin = GetWindow())
{
if (AslBase = OpenLibrary(AslName, 36))
{
if (FileRequester = AllocAslRequest(ASL_FileRequest, NULL))
{
*topath = '\0';
if (AslRequestTags(FileRequester, ASL_Hail, "Select Download Directory",
ASL_Window, mywin,
ASL_ExtFlags1, FIL1F_NOFILES,
TAG_DONE))
{
while(fgets(frompath, LEN_DOSPATH, logfile))
{
frompath[strlen(frompath)-1] = '\0';
fname = FilePart(frompath);
Print(frompath, PF_NOLF);
Print("... ", PF_NOLF);
strcpy(topath, FileRequester->rf_Dir);
if (strlen(topath))
if (topath[strlen(topath)-1] != ':')
strcat(topath, "/");
strcat(topath, fname);
if (*topath)
{
/* frompath nach topath kopieren */
if (Copy(frompath, topath, FALSE))
Print(":-)", 0);
else
Print(":-(", 0);
}
}
}
FreeFileRequest(FileRequester);
}
CloseLibrary(AslBase);
}
}
fclose(logfile);
}
else
SystemError("LocalDownload", "Logread");
}
///